
#include "sslserver.h"
#include "common.h"
#include <Core/logger/logger.h>

namespace Opl
{
    namespace Helpers
    {
        class SslServerPrivate
        {
            public:
                SslServerPrivate(): descriptor(-1)
                {}
                ~SslServerPrivate() {}
                int descriptor;
        };


        SslServer::SslServer(int descriptor):
            Ssl::SslBase(0), O_PRIVATE_CREATE(SslServer)
        {
            O_D(SslServer);
            d->descriptor = descriptor;
        }

        SslServer::~SslServer()
        {
            O_PRIVATE_DELETE;
        }

        void SslServer::start()
        {
            O_D(SslServer);
            Q_ASSERT(d->descriptor >= 0);
            LI.Info() << "SslServer::start(descriptor=" << d->descriptor << ")";
            Ssl::SslBase::start();
            socket()->setSocketDescriptor(d->descriptor);
            //socket()->setProtocol(QSsl::AnyProtocol);
            //socket()->setPrivateKey("server.key");
            //socket()->setLocalCertificate("server.crt");
            //if (!socket()->addCaCertificates("cacert.pem"))
            {
            //    LI.Error("Couldn't add CA certificates");
            //    return;
            }

            //socket()->startServerEncryption();
            setStatusInternal(Connected);
        }
    }
}
